class Solution
{
public:
    bool isPossibleDivide(vector<int> &nums, int k)
    {
        map<int, int> numCount;
        for (int num : nums)
        {
            ++numCount[num];
        }
        while (!numCount.empty())
        {
            int minVal = numCount.begin()->first;
            --numCount[minVal];
            if (numCount[minVal] == 0)
            {
                numCount.erase(minVal);
            }
            for (int val = minVal + 1; val < minVal + k; ++val)
            {
                if (numCount.count(val))
                {
                    --numCount[val];
                    if (numCount[val] == 0)
                    {
                        numCount.erase(val);
                    }
                }
                else
                {
                    return false;
                }
            }
        }
        return true;
    }
};